<?php
/**
 * Created by PhpStorm.
 * User: 64
 * Date: 2017/3/23 0023
 * Time: 14:26
 */
namespace app\web\controller;
use app\web\api\InsuranceApi;
use app\src\claim\logic\ClaimLogic;
use app\web\api\AccountScoreApi;
class Insurance extends  Weixin{
    protected function _initialize() {
        parent::_initialize();
        if (session("?memberinfo")) {
            $this->memberinfo = session("memberinfo");
        }else{
            $this->redirect('index/index');
        }
    }

//购买车险
    public function index(){
        $this->assignTitle('车险');

        return $this->fetch();
    }
    public function addcx(){
        if (session("?memberinfo")) {
            $this->memberinfo = session("memberinfo");
        }else{
            $this->error('请登录',url('login/login'));
        }
        $this->assignTitle('添加车辆');
        if(IS_POST) {
            $uid=$this->memberinfo['id'];
            $insurance_id=5;//保险类型
            $name=$this->_param('name');
            $car_code=$this->_param('car_code');
            $mobile=$this->_param('mobile');
            $id_front=$this->_param('id_front');
            $id_back=$this->_param('id_back');
            $driving_license_front=$this->_param('driving_license_front');
            $driving_license_back=$this->_param('driving_license_back');
            $annual_survey=$this->_param('annual_survey');
            $three_respons_insurance=$this->_param('three_respons_insurance');
            $his_insurance=$this->_param('his_insurance');
            $result = InsuranceApi::addApply($uid, $insurance_id, $name, $car_code,$mobile,$id_front,$id_back,$driving_license_front,$driving_license_back,$annual_survey,$three_respons_insurance,$his_insurance);
          // dump($result);exit;
            if (!$result['status']) {
                $this->error('添加失败','');
            }else{
                $this->success('添加成功', '');
            }
        }
        return $this->fetch();
    }
    public function cx(){

        $this->assignTitle('有车有保');


        $result=AccountScoreApi::getInfo('0',$this->memberinfo['uid']);

        if($result['status']) {
            $this->assign('score', $result['info']['score1']);

        }
        return $this->fetch();
    }

    public function Claim(){
        $this->assignTitle('理赔');
        $result = (new ClaimLogic)->claimList();
        if($result['status']){
            $this->assign('claimlist',$result['info']);
        }
        return $this->fetch();
    }

}